package com.sike.netty.im.client.service;


import com.sike.netty.im.common.command.LoginRequestCommand;
import com.sike.netty.im.common.command.Message;
import com.sike.netty.im.common.command.MessageBuilder;
import io.netty.channel.Channel;

import java.util.Scanner;

/**
 * 登录接口
 *
 * @author chenssy
 * @date 2023/09/15
 */
public class LoginService {
    /**
     * 登录
     * @param channel
     */
    public void login(Channel channel) {
        new Thread(() -> {
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入用户名:");
            String username = scanner.nextLine();
            System.out.println("请输入密码：");
            String password = scanner.nextLine();

            LoginRequestCommand loginRequestCommand = new LoginRequestCommand(username,password);
            Message message = MessageBuilder.buildMessage(loginRequestCommand,username,null);
            channel.writeAndFlush(message);
        }).start();
    }

    /**
     * 主界面
     */
    public void mainMenu() {
        System.out.println("|-------------------------------------|");
        System.out.println("|               主界面                 |");
        System.out.println("|    01:单聊              02:群聊      |");
        System.out.println("|    03:建群              04:查群成员   |");
        System.out.println("|    05:加群              06:退群      |");
        System.out.println("|    00:退出登录                       |");
        System.out.println("|-------------------------------------|");
    }
}
